﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExpressionEngine
{
    /// <summary>
    /// 乘法处理器
    /// </summary>
    public class MultiplyOperatorHandler : OperatorHandler
    {
        /// <summary>
        /// 乘法处理
        /// </summary>
        /// <param name="oper"></param>
        /// <returns></returns>
        public override Variable operate(OperationSymbol oper)
        {
            if (!base.validate(oper))
                throw new Exception("减法操作符参数错误");

            DataType varDataType = base.ValidateVarDataType(oper.Operands);
            Variable res = new Variable();
            switch (varDataType)
            {
                case DataType.INT:
                case DataType.FLOAT:
                case DataType.DOUBLE:
                    {
                        double intValue = double.Parse(oper.Operands.First().Value.ToString())
                            * double.Parse(oper.Operands.Last().Value.ToString());
                        res.ValueType = DataType.DOUBLE;
                        res.Value = intValue;
                    }
                    break;
                default:
                    throw new Exception("出现非法数据类型");
            }

            return base.ForName(res);
        }
    }
}
